<?php
class Del_View_Helper_AreaToJson 
	extends Zend_View_Helper_Abstract
{

	public function areaToJson( $area )
	{
		if ( $area instanceof Delivery_Model_Zona ){
		
			$ob	= $this->_getObject( $area );
			return Zend_Json::encode( $ob );
		}
		
		if ( is_array($area) || $area instanceof Delivery_Model_Collection_Zonas){
			return $this->areasToJson( $area );
		}	
		
	}
	
	public function areasToJson( $areas )
	{
		$_json = array();
		
		foreach ($areas as $area){
			$_json[] = $this->_getObject( $area );
		}
		
		return Zend_Json::encode( $_json );
	}
	
	protected function _getObject( $area )
	{
	
		$ob					= new stdClass();
		$ob->name			= $area->nombre;
		$ob->price			= $area->precio;
		$ob->minimumPurchase= $area->compraMinima;
		$ob->coordinates	= $area->coordenadas;
		
		return $ob;
	}
	

}